package com.zkingsoft.services.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zkingsoft.dao.UsersDao;
import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.model.Users;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.serviceUtil.ServiceUtil;
import com.zkingsoft.services.CompanyService;
import com.zkingsoft.services.FunctionService;
import com.zkingsoft.services.RolePwoerService;
import com.zkingsoft.services.UsersService;
import com.zkingsoft.syslog.SysLogService;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2016-04-22 08:43
 */
@Service("usersService")
public class UsersServiceImpl implements UsersService {

	@Autowired
	private UsersDao usersDao;
	@Resource
	private FunctionService functionService;
	@Resource
	private RolePwoerService rolePwoerService;
	@Resource
	private CompanyService companyService;

	@Resource
	private SysLogService logService;
	@Autowired
	private ServiceUtil serviceUtil;

	/**
	 * 当前service对应的表的名称
	 */
	public final String TABLE = "users";

	@Override
	public int add(Users users) {
		// 校验账号是否重复
		if (serviceUtil.addCheckRepeat(TABLE, "account", users.getAccount())) {
			throw new GlobleException("账号已注册!");
		}
		// 校验email是否重复

		if (serviceUtil.addCheckRepeat(TABLE, "email", users.getEmail())) {
			throw new GlobleException("email已注册!");
		}

		return usersDao.insert(users);

	}

	@Override
	public int modify(Users users) {
		users.getPassword();
		// 校验账号是否重复
		if (serviceUtil.updateCheckRepeat(TABLE, "account", users.getAccount(), "id", users.getId())) {
			throw new GlobleException("账号已注册!");
		}
		// 校验email是否重复
		if (serviceUtil.updateCheckRepeat(TABLE, "email", users.getEmail(), "id", users.getId())) {
			throw new GlobleException("email已注册!");
		}
		return usersDao.update(users);

	}

	/**
	 * 
	 * @Description: 删除方法是逻辑删除
	 * @author:姜友瑶
	 * @param list
	 * @return
	 * @date 2016年8月31日
	 */
	@Override
	public int remove(List<Long> list) {
		return usersDao.deleteByIds(list);
	}

	/**
	 * 
	 * @Description: 删除方法是逻辑删除
	 * @author:姜友瑶
	 * @param list
	 * @return
	 * @date 2016年8月31日
	 */
	@Override
	public int removeById(Long id) {

		return usersDao.deleteById(id);

	}

	@Override
	public List<Users> findInPage(Users users, PaginationVO pageVo) {

		return usersDao.selectInPage(users, pageVo);

	}

	@Override
	public List<Users> findByModel(Users users) {

		return usersDao.selectByModel(users);

	}

	@Override
	public int findTotal(Users users) {

		return usersDao.selectTotalRecord(users);

	}

	@Override
	public Users findById(Long id) {

		return usersDao.selectById(id);

	}

	@Override
	public List<Users> findByIdStr(String idStr) {
		
		return usersDao.selectByIdStr(idStr);
	}
	
	@Override
	public List<Users> findHistorical(PaginationVO pageVo){
		
		return usersDao.selectHistorical(pageVo);
	}
	@Override
	public List<Users> Mentor(Users users,PaginationVO pageVo) {

		return usersDao.selectMentor(users,pageVo);

	} 
	
	@Override
	public int totalMentor(Users users) {

		return usersDao.selectTotalMentor(users);

	}

	@Override
	public List<Users> selectUsers() {
		return usersDao.selectUsers();
	}
}